import type {RouteRecordRaw} from "vue-router";
import {createRouter, createWebHashHistory} from "vue-router";

import HomeView from '@/views/HomeView.vue'
import Login from '@/views/login/index.vue'
import Dashboard from '@/views/dashboard/index.vue'
import UserList from '@/views/user/index.vue'
import FlowDraw from '@/views/flow/index.vue'

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
    {
        path: "/login",
        name: "login",
        component: Login,
        meta: {hidden: false, requireAuth: false},
    },
    {
        path: '/',
        redirect: '/dashboard', // 根路径默认重定向到 /dashboard
        name: 'home',
        component: HomeView,
        children: [
            {
                path: 'dashboard',
                component: Dashboard,
                meta: {title: '首页仪表盘', icon: 'el-icon-s-home', requireAuth: true},
            },
            {
                path: 'userList',
                component: UserList,
                meta: {title: '用户列表', icon: 'el-icon-s-home', requireAuth: true},
            },
            {
                path: 'flowDraw',
                component: FlowDraw,
                meta: {title: '流程绘制', icon: 'el-icon-s-home', requireAuth: true},
            },
        ]
    }
];

/**
 * 创建路由
 */
const router = createRouter({
    history: createWebHashHistory(),
    routes: constantRoutes,
    // 刷新时，滚动条位置还原
    scrollBehavior: () => ({left: 0, top: 0}),
})

/**
 * 重置路由
 */
export function resetRouter() {
    router.replace({ path: "/login" });
}

export default router
